def main():
    m = int(input())
    for _ in range(m):
        word = input().strip()
        for char in word:
            if char.islower():
                print(char.upper(), end='')
            else:
                print(char.lower(), end='')
        print()


main()
